package com.yidu.StockControl.controller;

import com.yidu.StockControl.entity.SecurityInventory;
import com.yidu.StockControl.entity.TAInventory;
import com.yidu.StockControl.service.TAInventoryService;
import com.yidu.Util.util.Dbutil;
import com.yidu.Util.util.TableIdUtil;
import com.yidu.Util.util.TableNameUtil;
import com.yidu.Util.util.TableTimeUtil;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class TAInventoryController {
    @Resource
    private TAInventoryService taInventoryService;
    @Autowired
    Dbutil dbutil;

    @RequestMapping("/selectTAInventory")
    public Map selectTAInventory(String statisticsDate,String fundId, int page, int limit){
        List<TAInventory> list = taInventoryService.selectTAInventory(statisticsDate,fundId,page, limit);
        int count = taInventoryService.selectTAInventoryCount();
        Map map = new HashMap();
        map.put("code", "0");
        map.put("msg", ":");
        map.put("count", count);
        map.put("data", list);
        return map;
    }

    @RequestMapping("/insertTAInventory")
    public int insertTAInventory(TAInventory taInventory, HttpServletRequest request){
        HttpSession session = request.getSession();
        String fundId = (String) session.getAttribute("fundId");
        String maxId3 = dbutil.getMaxId3(TableIdUtil.TASID, TableNameUtil.TAI, TableTimeUtil.TASTime, taInventory.getStatisticsDate());
        taInventory.setStatisticsDate(maxId3);
        taInventory.setFundId(fundId);
        int i = taInventoryService.insertTAInventory(taInventory);
        return i;
    }

    @RequestMapping("/updateTAInventory")
    public void updateTAInventory(TAInventory taInventory){
        taInventoryService.updateTAInventory(taInventory);
    }
    @RequestMapping("/deleteTAInventory")
    public void deleteTAInventory (String taInventoryId) {
        taInventoryService.deleteTAInventory(taInventoryId);
    }
}

